home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / newsgroups / misc.20000824-20010305 / 000381_news@columbia.edu _Sat Mar 3 11:19:58 2001.msg < prev    next >
Internet Message Format  |  2020-01-01  |  5KB

  1. Return-Path: <news@columbia.edu>
  2. Received: from newsmaster.cc.columbia.edu (newsmaster.cc.columbia.edu [128.59.59.30])
  3.     by fozimane.cc.columbia.edu (8.9.3/8.9.3) with ESMTP id LAA24331
  4.     for <kermit.misc@cpunix.cc.columbia.edu>; Sat, 3 Mar 2001 11:19:58 -0500 (EST)
  5. Received: (from news@localhost)
  6.     by newsmaster.cc.columbia.edu (8.9.3/8.9.3) id LAA23091
  7.     for kermit.misc@watsun.cc.columbia.edu; Sat, 3 Mar 2001 11:17:53 -0500 (EST)
  8. X-Authentication-Warning: newsmaster.cc.columbia.edu: news set sender to <news> using -f
  9. From: fdc@columbia.edu (Frank da Cruz)
  10. Subject: Re: FTP - loops and parameters for multifile reading
  11. Date: 3 Mar 2001 16:17:53 GMT
  12. Organization: Columbia University
  13. Message-ID: <97r5fh$mhh$1@newsmaster.cc.columbia.edu>
  14. To: kermit.misc@columbia.edu
  15.  
  16. In article <3AA06BF9.7F392836@aol.com>,
  17. Paul Nestler  <prnestler@aol.com> wrote:
  18. : Does anyone know how to put ftp inside a loop?  Say, a loop that
  19. : generates a list of filenames to download?
  20. : Here's the background:
  21. : I have a problem connection I am dealing with.  When transferring a
  22. : number of files using mget in ftp, the connection hangs and aborts.  The
  23. : point at which the ftp session hangs varies from one session to the
  24. : next, but so far has always allowed me to transfer a few files before it
  25. : hangs.
  26. : I looked at the man page for ftp.  The man page discusses a looping
  27. : feature and the ability to pass a parameter (from the calling script I
  28. : suppose).  Unfortunately, the man page does not show an example nor does
  29. : it describe the usage in any useable detail.
  30. : The man page gave me the notion I should be able to put the ftp inside a
  31. : loop and pass the name of a file to get from the remote host.  Perhaps
  32. : there is someway of putting the ftp inside an awk script.
  33. Let's see how we would do this with the new scriptable C-Kermit FTP
  34. client.  Let's assume an anonymous login, though it need not be, and that
  35. the files are to be transferred in binary mode, and that the filenames
  36. are file1 through file5:
  37.  
  38.     while true {
  39.     ftp open somehost.com /anonymous
  40.     if fail {
  41.         Can't reach host           ;  Can't make connection
  42.         sleep 10*60                ;  Wait 10 minutes and try again
  43.         continue
  44.     }
  45.     ftp cd somedirectory
  46.     if fail {
  47.         exit 1 Fatal - can't CD to somedirectory on host        
  48.     }
  49.         while true {
  50.             ftp mget /binary /recover file1 file2 file3 file4 file5
  51.             if success goto done        ;  All files downloaded: done.
  52.             if not \v(ftp_connected) {  ;  Failed - why?
  53.                 ftp close               ;  Connection closed
  54.                 break                   ;  Go back and make a new one
  55.             }
  56.             ; Connection still open - try MGET again.
  57.             echo "Download failed - trying again in 20 seconds..."
  58.             sleep 20
  59.         continue
  60.         }
  61.     }
  62.     :done
  63.     ftp bye                             ;  Disconnect from server
  64.     exit 0                              ;  Exit successfully
  65.  
  66. This is a very straightforward example, with hardwired host, directory,
  67. and filenames.  Of course these could also be variables that could be
  68. resolved in various ways, e.g. from command-line options, with interactive
  69. prompting, or from a file.
  70.  
  71. The loop connects to the host, cd's to the desired directory, and requests
  72. the files in binary mode.  Each step is checked for failure and is retried
  73. until it succeeds.  Of course you could use a counted loop rather than an
  74. infinite loop if you wished, and you could use different sleep intervals
  75. or none at all.
  76.  
  77. In this example, failure to connect results in a 10-minute pause (assuming
  78. the host is down or unavailable) and then a loop restart.  You could make
  79. it do anything else that might be more appropriate.
  80.  
  81. The magic command is MGET /BINARY /RECOVER <file-list>.  For each file in
  82. the list:
  83.  
  84.  . If the file does not exist on the client, it is downloaded; otherwise:
  85.  
  86.  . If a file of the same name exists on the client, the client requests
  87.    the host file's size and modification date-time; if the date-time and
  88.    size are the same, the file is skipped; otherwise:
  89.  
  90.  . If the date-time is later, the file is downloaded, overwriting the
  91.    client's copy (which is backed up for safety); otherwise:
  92.    
  93.  . If the size is greater, the excess part of the host file is downloaded
  94.    and appended to the client file.
  95.  
  96. The MGET command is in an inner loop, which retries the MGET command as
  97. long as it fails and the connection is open.  If MGET fails because the
  98. connection was closed, the outer loop is continued and a new connection is
  99. made.  Thus no file is transferred more than once, and if a transfer fails
  100. in the middle of a file, it is resumed from the point of failure next time
  101. through the loop.
  102.  
  103. For more information about the C-Kermit FTP client, see:
  104.  
  105.   http://www.columbia.edu/kermit/ftpclient.html
  106.  
  107. And for a tutorial on scripting the new FTP client, see:
  108.  
  109.   http://www.columbia.edu/kermit/ftpscript.html
  110.  
  111. The new FTP client is still in prerelease testing but should be perfectly
  112. usable, and should be formally released soon.   A prebuilt binary for AIX 
  113. 4.3.2 can be downloaded from C-Kermit 7.1 site:
  114.  
  115.   http://www.columbia.edu/kermit/ck71.html
  116.  
  117. as well as the source code and binaries for many other platforms.
  118.  
  119. - Frank